Fully worked out LIB. Testing needed