Refactored
Probably final Homework version :)