functions simplified;
cos optimized;