This is messy and needs cleaning up