Refactor

    - Use array instead of dictionary with integer keys
    - Use properties rather than ivars
    - Hide properties that don't need to be public in the implementation
    - Improve some variable names
    - Move the hacky bugfix methods to the bottom