fix tests (custom alert error), refactor some code