Refactor whole layer

I still have no idea what it's doing