changed outputs and moved arraytopolys within functions