Edited code with Phil's answers