Fixed bugs and code cleanup in server

Signed-off-by: Cory Feitelson <cfeitelson@roovy.com>