added comments
improved design