Better error handling and comments. Comments need to be finished though.