Add comments and eliminate magic number
Use type inference in loops