cleanup

cleaned up code replaced passing multiple optional arguments with one argument array
Stored api code in class object instead of having to provide it every function call