check socket bound status properly

also some small refactoring on socket binding.

closes #180