Split between main and library.
Moved library file into proper place.