refactor tests and if bugfix