polished the code a bit, added some more tests and removed a deprecated API call