finished code for tilecoder