Added main and jail, fixed some bugs