code almost ready for server