Fix various bugs, new features, still unfinshed.