Functioning code. Statistics still work in progress.