adds comments and code refactor