Fixed bugs. Added cycle buffer

Fixed some bugs after code review. Added cycle buffer realization.