Modify function names to be more consistent.

Replace magic numbers for HTTP status codes with defined object.

other stylistic changes to match conventional JavaScript syntax.