Changed the API a bit and fixed some small bugs