Not Pretty but it works