Made code more DRY, removed line content printing and integrated level into error message.