Added basic Layer support

Added Layers, and that introduced some new bugs. I fixed most of them,
but it's probably still buggy right now. Also the interface sucks.