fixed most of the rest of the perl code!