code cleanup & fixes