Work in progress. Code cleanup