Changed some stuff around

Added api
Changed some function to utilize the api
fixed several bugs