Changed range() function according to python3 and corrected some errors