added coin counting function