fixed bugs + refactor np.py