long messy solution