Refactor code as well as commenting