major changes to library structure, add ref option and small test