Code refactoring and making it work with custom frame range.