Fixed a bug on a test and refactored a bit.