code improvement and cleanup