Fixed various bugs and change structures