Fix and refractor code for video player