This code should be moved into a directive