fixed infinite loop bug, improved MVC mechanism