added balance checking and count functions