Refactored to split input into list[][] instead of just removing the spaces.