Some performance improvement and comments added