added comments, implemented unit testing