added else; fixed while;