updated with minor bug