Removed unnecessary catch blocks
REFACTOR extracted duplicate connection code
Added test for getHeader
Replaced length function with Java 7 equivalent