fixed background draw order and cleaned up some code