added in complex part, simplified functions