added and corrected moataz's script