Code factoring + comments