Removed duplicated code. Replacing char arrays with strings where was convenient