casting tests and refactoring