Cleaned up toggleLayer method