initial code done by mohsen