several bugs found, need to debug