Addressed Simon's comments and make it pass tests