Refactor code\nUse bounds instead of frame wherever required. Add documentation. Remove some magic numbers.