Lab 3 refactored, better error handling.