Cleanup and replaced end with length
Fixed error
Added tests