ugly code :(