Code cleanup and logic improvement
More elegant parser and connection manager