Now works correctly, but still uses immediate mode