A bit of refactoring and bug fixing

I think the service actually works now!