modified the code a little bit