Changed functions to be more modular for easier dynamic implementation