Fixed arguments and cleaned up code a bit