Updated the popup code and split into separate files