Some more robustness + error checking. Closes #4