fixed subsource select statement, other bugs, refactor of server api to new file