made import error handling explicit
refactored server code for readability and reuse