Statistics and database added, small bug fixes