works but hacky, much cleanup required