Code cleanup and working