commenting the code + minor improvements