Refactored and fixing tests