Full code review

Main should be at the bottom.