Add debug facilities, make API routes better