Cleaned up code, still a bug between IN/OUT processing steps.