This code may be a bit outdated and the conditions I used to create this were not the best. If you want to adapt something like this, please make required corrections.