Fixed some bugs and preliminary support for subdomain api