Fixed and refactorized test