Code cleanup + logging