Jail and core code refactored