Refactored the code according to the feedback recieved in #212