Works except for one really annoying bug