fixed bugs, tested with Server