fixed all potential bugs. need to tune parameters