Web Api fixes and code refactoring