Removed API dependency and cleaned up some code