Fixed bugs when call log in API. Cleaned up some code.