cleaned and fixed the code a little