Fixed a couple bugs from the previous implementation