optimization of some scripts