Refactored source and scripts