added main loop and data - performance is not ideal but it works