minor improvement
fix bugs and make controller more robust