Implemented using objects
Added testling
Modified so that theres no outer function