Cleaned up and fixed multipass code