Fixed a bug and simplified functions