code refactor, bugfix