Refactored server code. Fixed a bug in core/math