this is a lot of code replication...but I'm not sure what can be done about it.