added lots of library code