Abstracted error handling, moved comments