Moved and organized functions