Added dynamic input allocation and cleaned up some trailing whitespace.