Code cleanup and simplification