code cleanup and lg file fixes