completed assignment 6, nasty code though