Working library

Some bugs fixed