Optimized code and added noteLength