WIP rewrite of php code so that code is more generalized and will work for all cases. Still broken for new lines