[refac] House cleaning

* mainly moved things around, separation of typedefs for easier inlusion
* maked layers to be smaller in terms of the memory
* layers created via factory faster