incorporated mengxr's code style suggestions