fixed various bugs, added a few extra functions.