Started new version of serial code using snippets from the original code. Some refactoring.