tried to take some inspiration from @huiro