Fixed a bug with the focusOut event and modularized the code.