Optimize image capturing a bit, program still not working, though