Fixed more bugs and better error msgs