Moved main script to new file and added control interface.