Fixed several bugs

Fixed bugs with $tokenProvider when setting endpoints
Added more tests