Functions, bug fixes, preparation for if-else