v0.5.5: Fix problem with active layer detection. Code cleanups.