Refactored and fixed bugs. Now all arguments go through the same loop.