added port number
refactoring and clean up