revised code a bit