Added array modularization

Also rearranged some function and added singleinstances to all scripts.