fixed NPE

added timeout configuration
better way of handling InterruptedException