refactored script and added some methods on media class