Refactored sprite flickering functionality - a big thanks to ghost