Use arrays instead of stdClass, refactoring, various functions