For issue #16, fixed many small code style issues, to make the code easier to understand