edited code a bit