Removed unraised code
Added custom average function