Code restructure and basic input handling