More modular version of basic code