Fixed many bugs, closes #5