added sample output
fixed brain fuck and merged ifs for clarity