[fix] removed the probability of undefined behaviour

This is related to the strict aliasing, C std doens't guarante that the structure type casted on different structure type will work, so I've decided to remove unneded 'mid' type and use only one generic type do describe layers.