Improve readability of code and fix some mistakes