Some refactoring. Fixed endpoint transform bug