reimplemented and passed most tests