massive refactor of tilelayer