Tidied up some code, and updated api parameter order