Refactored to support SDL2