Fixed code problems as per Ivo's Review