added server error reply
refactorin
more refactoring
refactored crypto into another method