-cleaned up code (still has an error that I can't figure out atm)