Improve readability by indenting newline
Remove redundant casts, tidy up braces, remove confusing arithmetic