...too late to edit: I missed "return" in the second piece of code, right after the opening {-bracket