Fixed while and added write() for no \n printing