implemented rests, some bugs correction