Added dynamic input allocation and stripped of some trailing whitespace.