Minor improvements
various code reworking