tile selection implemented, restructured javascript