debug mode added for final checks. further annotations and improvement to main input loop