Fix long parameter parsing and refactor code