Add comments and improve organization