Some code reworking