Improve code quality

Add docstrings, remove dead code and do some other small tweaks.
Move tile URL generation to a core module
Fix missing import
Improve tile handling code

The main improvement is to use lzxy tuples
instead of passing a bazillion of coordinates
and other information tidbits.
This alone makes the code much more managable
and removes a lot of code getting layer from
layer id over and over again.
Also use the factored-out tile URL generating
 function and many other improvements.