Mostly resolving iss99, refactoring