updated with a few bug fixes