Eliminated unnecessary writing of 0 length data.
Input refactoring...