Code cleanup & general improvements