Added play function and some optimizations