Improved code handlinge the right media source