added a condition to check the width of the viewport

PLEASE DO NOT MERGE YET.