this was much harder than i thought