fixing some things and making the refactor function again