added a few assertions, deleted some unnecessary brackets, fixed return type