code cleanup and sanitizing inputs