More AppleScript refinement

Made subroutines for better code management, logic, and execution.
Still not perfect, but I think it will work as a roll-your-own solution.