Updated code after code review by Slam