Initial commit, cleaned up version of existing code plus a few additions