added stats file and moved some code