Changes after code review by Thomas