minor edits, simplifying main.cpp and adding core functionality to rlib.cpp