Replaced some for-loops with more idiomatic functional sequence operation;
fixed typo