made util and apply it to frame.py, moreover fix bug