refactor bugs fixed