Rewritten tile related code