More code cleanup and refoactors