Improved layer rendering and code clean-up