a few fixes and cleaning up
encapsulating server function in servercore module