lib: fixes a serious bug that it could not deal with cyclic dependencies; #125
test: adds more cases for cyclic dependencies; #125
ready: optimize logic; #125