improved comments and code tidiness